/**********************************************************


***********************************************************
File Name		     : ExceptionManager.cs
Project Code		 : 
Author  			 : 
Created on	    	 : 
***********************************************************
Type		    	 : C# Source file
Purpose			     : This class has static method to switch 
                       between database logger and file logger
Pre-requisites		 : 
Known Bugs		     : 
Associated File(s)	 :
Table(s)/Procedure(s):
Method(s)    		 : overloaded methods Publish
See Also			 :
***********************************************************
Revision History	 :


***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Data;

namespace ExceptionLogger
{
    public class ExceptionManager
    {

        /// <summary>
        /// Method to log the Exception.Logs the Error in the database, 
        /// if logging to database is not possible then it will log to a logfile.
        /// </summary>
        /// <param name="Exc"></param>
        /// <param name="userName"></param>
        public void Publish(Exception Exc, string userName)
        {
            object exceptionMessage = new object();

            exceptionMessage = Exc;

            try
            {
                if (System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_HOST"] != null)
                    DBLogger.WriteToDB(exceptionMessage as Exception, System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_HOST"], userName);
            }
            catch
            {
                FileLogger.WriteToFile(exceptionMessage as Exception, System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_HOST"], userName);
            }
        }

        /// <summary>
        /// Method to log the exe run status messages in the file log
        /// </summary>
        /// <param name="Exc"></param>
        /// <param name="userName"></param>
        public void Publish(string logMessage)
        {
            FileLogger.WriteToFile(logMessage);
        }

    }
}
